/*
 * @Author: szx
 * @Date: 2022-04-14 13:22:12
 * @LastEditTime: 2022-04-14 13:28:11
 * @Description:
 * @FilePath: \leetcode\剑指offerII\059\059.cpp
 */
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

class KthLargest {
   public:
    priority_queue<int, vector<int>, greater<int>> q;
    int k;
    KthLargest(int k, vector<int>& nums) {
        this->k = k;
        // 从小排到大，（默认是从大排到小）
        for (int i : nums) {
            add(i);
        }
    }

    int add(int val) {
        q.push(val);
        if (q.size() > k) {
            q.pop();
        }
        return q.top();
    }
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */